using System;
using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;


[Serializable]
/// <summary>
/// 跟随,一个物体跟随另外一个物体，Target是被跟随的物体，Tracker是跟随的物体
/// </summary>
public class TrackedComponent
{
    public Transform _Target;
    public Transform _Tracker;
    [ReadOnly]
    public Vector3 InitTrackerPos;
    [ReadOnly]
    public Vector3 InitTargetPos;
    [ReadOnly]
    public Vector3 InitPosDistance;
    [ReadOnly]
    public Vector3 TrackPos;

    private bool IsTracker;


    public void Init(Transform tracker, Transform target)
    {
        _Target = target;
        _Tracker = tracker;
        InitTrackerPos = tracker.transform.position;
        InitTargetPos = target.transform.position;
        InitPosDistance = InitTrackerPos - InitTargetPos;
        IsTracker = false;
    }

    public void Update()
    {
        TrackPos = _Target.transform.position + InitPosDistance;
        if (IsTracker)
        {
            _Tracker.transform.position = TrackPos;
        }
    }

    public void StopTrack()
    {
        IsTracker = false;
    }

    public void StartTrack()
    {
        IsTracker = true;
    }
}
